package cn.stu.system.controller;


import cn.stu.common.utils.ApiData;
import cn.stu.framework.dto.LoginLogDto;
import cn.stu.framework.entity.LoginLog;
import cn.stu.framework.service.LoginLogService;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录日志控制器
 *
 * @author 郑志豪
 * @date 2023/11/06
 */
@RestController
@RequestMapping("/loginLog")
@AllArgsConstructor
public class LoginLogController {
    private LoginLogService sysLoginLogService;

    /**
     * 分页查询部门数据
     *
     * @param logDto 日志数据转换器
     * @return {@link ApiData}
     */
    @ApiOperation("分页获取数据")
    @GetMapping("/page")
    public ApiData page(LoginLogDto logDto) {
        sysLoginLogService.lambdaQuery()
                .like(StringUtils.isNotBlank(logDto.getAcc()), LoginLog::getAcc, logDto.getAcc())
                .likeRight(StringUtils.isNotBlank(logDto.getIpaddr()), LoginLog::getIpaddr, logDto.getIpaddr())
                .ge(logDto.getStartTime() != null, LoginLog::getCreateTime, logDto.getStartTime())
                .le(logDto.getEndTime() != null, LoginLog::getCreateTime, logDto.getEndTime())
                .orderByDesc(LoginLog::getCreateTime)
                .page(logDto);
        return ApiData.getPageTrue("获取成功", logDto.getTotal(), logDto.getRecords());
    }
}
